import { getToken, removeToken, setToken } from '@/utils/token';
import { createSlice } from '@reduxjs/toolkit';

export const authSlice = createSlice({
  name: 'auth',
  initialState: {
    token: getToken() || ''
  },
  reducers: {
    setToken: (state, action) => {
      state.token = action.payload;
      setToken(action.payload);
    },
    resetToken: (state) => {
      state.token = '';
      removeToken();
    }
  }
});

export default authSlice;
